package com.yu.common.config.property;

import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Data
@Configuration
public class WeixinProperty {
    @Value("${my.properties.wx.appid}")
    private String appid;

    @Value("${my.properties.wx.appSecret}")
    private String appSecret;

    @Value("${my.properties.wx.mchId}")
    private String mchId; // 个人商户号

    @Value("${my.properties.wx.mchKey}")
    private String mchKey;

    @Value("${my.properties.wx.notifyUrl}")
    private String notifyUrl; // 回调地址

    @Value("${my.properties.wx.keyPath}")
    private String keyPath;


    @Bean
    public WxPayService wxPayService() {
        return new WxPayServiceImpl() {
            @Override
            public WxPayConfig getConfig() {
                WxPayConfig wxPayConfig = new WxPayConfig();
                wxPayConfig.setAppId(appid);
                wxPayConfig.setMchId(mchId);
                wxPayConfig.setMchKey(mchKey);
                wxPayConfig.setNotifyUrl(notifyUrl);
//                wxPayConfig.setKeyPath(keyPath);
                return wxPayConfig;
            }
        };
    }
}
